package com.isamarasinghe.srisinhala.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class URLConnectionReader {
	public static String read(String url) throws Exception {
		if (!url.startsWith("http"))
			url = "http://" + url;

		URL urlObj = new URL(url);
		URLConnection yc = urlObj.openConnection();
		BufferedReader in = new BufferedReader(new InputStreamReader(
				yc.getInputStream(), "UTF-8"));
		StringBuilder output = new StringBuilder();
		String inputLine;
		while ((inputLine = in.readLine()) != null) {
			output.append(inputLine);
		}
		in.close();
		return Sinhala.getInstance().replace(output.toString());
	}
}